package database;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;

import com.labmi.experiment.ClothingItem;
import com.labmi.experiment.Item;

public class PopulateDB {
	
	
	public static void main(String[] args) {
		java.util.Map<Object,Object> map = new java.util.HashMap<Object,Object>();
		EntityManagerFactory factory = Persistence.createEntityManagerFactory("shopping", map);
		EntityManager em = factory.createEntityManager();
		
		EntityTransaction entr=em.getTransaction();
	      entr.begin();
		
		Item item = new ClothingItem();
		
		item.setPrice(30);
		
		
		em.persist(item);
		
		entr.commit();
		Query queryResult = em.createQuery("SELECT x  FROM Item x");
		
		List<Item> resultList = queryResult.getResultList();
		for (Item anItem : resultList) {
			System.out.println(anItem.getName() + "  " + anItem.getPrice());
		}
		
		
		em.close();
		factory.close();
	}
}
